package vpfarm.master;

import jtools.ai.agenten.AMessage;
import jtools.ai.agenten.CycleBehavior;
import vpfarm.Constants;
import vpfarm.data.JobInfo;

public class AcceptSlavesBehavior extends CycleBehavior {

	private JobInfo jobInfo;

	public AcceptSlavesBehavior(JobInfo ji) {
		this.jobInfo = ji;
	}

	@Override
	public void execute() {
		AMessage msg = myAgent.reciveMessage(true);
		if (msg.getSubject() == Constants.REGISTER_SLAVE){
			try{
				AMessage rep = msg.createReplay(Constants.SEND_JOB_INFO);
				rep.setContent(new JobInfo(this.jobInfo));
				myAgent.sendMessage(rep);
			}catch (Exception e) {
				e.printStackTrace();
			}
		}else
			myAgent.pushBack(msg);
	}

	public void onEnd() {
	}

	public void onStart() {
	}

}
